import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/emergency/emergency_event_list_entity.dart';

/// 事故事件报警
class AccidentAlarm extends StatelessWidget {
  const AccidentAlarm({super.key});

  /// 基本信息
  Widget _buildBasicInfoItem(
    String key,
    String val,
    bool isRequired, {
    bool isPic = false,
  }) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
      child: Row(
        children: [
          SizedBox(
            width: 120.w,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                if (isRequired)
                  Text(
                    '*',
                    style: TextStyle(
                      fontSize: 13.sp,
                      color: Colors.red,
                    ),
                    textAlign: TextAlign.center,
                  ),
                Text(
                  key,
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: const Color(0xFF7C7D93),
                  ),
                )
              ],
            ),
          ),
          isPic
              ? SizedBox(
                  height: 77.w,
                  width: 77.w,
                  child: Image.network(val),
                )
              : Expanded(
                child: Text(
                    val,
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: const Color(0xFF495061),
                    ),
                  ),
              ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final EmergencyEventListEntity item = Get.arguments as EmergencyEventListEntity;
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Container(
            height: AppDimens.dp12,
            color: AppColors.bg_color_grey,
          ),
          Container(
            height: AppDimens.dp2,
            color: AppColors.blue_button,
          ),
          Container(
            height: AppDimens.dp40,
            width: AppDimens.sw,
            color: const Color(0xFFF4F7FF),
            alignment: Alignment.centerLeft,
            child: Container(margin: EdgeInsets.only(left: AppDimens.dp40), child: Text('事故事件名称：${item.accidentName}', style: AppTextStyles.black_16)),
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  _buildBasicInfoItem('接警人', '${item.answerPoliceName}', true),
                  _buildBasicInfoItem('报警人', '${item.callPoliceName}', true),
                  _buildBasicInfoItem('报警电话', '${item.callPolicePhone}', true),
                  _buildBasicInfoItem('事故类型', '${item.accidentTypeLabel}', true),
                  _buildBasicInfoItem('事故装置', '${item.accidentDevice}', true),
                  _buildBasicInfoItem('涉及危险化学品', '${item.chemicalTypeNameList}', true),
                  _buildBasicInfoItem('接警时间', '${item.policeAnswerDate}', true),
                  _buildBasicInfoItem('事故发生时间', '${item.accidentStartDate}', true),
                  _buildBasicInfoItem('已采取措施', '${item.accidentAnswerType}', true),
                  _buildBasicInfoItem('死亡人数', '${item.deathNum}', false),
                  _buildBasicInfoItem('重伤人数', '${item.seriousInjuryNum}', false),
                  _buildBasicInfoItem('轻伤人数', '${item.minorWoundNum}', false),
                  Container(
                      padding: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
                      alignment: Alignment.centerLeft,
                      child: Text('事故现场照片',
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: const Color(0xFF7C7D93),
                          ))),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
                    alignment: Alignment.centerLeft,
                    child: Wrap(
                      spacing: 10.w,
                      runSpacing: 10.w,
                      children: item.accidentScenePhotos.map(_buildPicItem).toList(),
                    ),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildPicItem(String url) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: SizedBox(
        height: 77.w,
        width: 77.w,
        child: Image.network(
          url.startsWith('http') ? url : Interface.fileUrl + url ,
          fit: BoxFit.cover,),
      ),
    ).clickShowLarge(
      url:  url.startsWith('http') ? url : Interface.fileUrl + url ,
    );
  }
}
